package com.atguigu03.date.jdk8;

import org.junit.Test;

import javax.xml.crypto.Data;
import java.time.*;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeFormatterBuilder;
import java.time.temporal.TemporalAccessor;
import java.util.Date;

/**
 * ClassName: Jdk8
 * Package: com.atguigu03.date.jdk8
 * Description:
 *
 * @Author BuTang
 * @Create 2023/5/24 15:54
 * @Version 1.0
 */
public class Jdk8 {
    @Test
    public void test1(){
        LocalDate date1 = LocalDate.now();
        LocalTime date2 = LocalTime.now();
        LocalDateTime date3 = LocalDateTime.now();

        System.out.println(date1);
        System.out.println(date2);
        System.out.println(date3);

        //ofEpochDay里面是添加时间戳的
        Date date = new Date();
//        System.out.println(date.getTime());
//        System.out.println();

        System.out.println("**********");
        System.out.println(Instant.ofEpochMilli(System.currentTimeMillis()));
        System.out.println("**********");

//        System.out.println();

        //方法的测试
        System.out.println(date1.getYear());


        Instant i = Instant.now();
        System.out.println(i.toEpochMilli());

        Date qq= new Date();
        System.out.println("你好#######:"+qq.getTime());


    }

    @Test
    public void test2(){
        Instant i = Instant.now();
        System.out.println(i);

        Date date = new Date();

        Instant i1 = Instant.ofEpochMilli(date.getTime());
        System.out.println(i1);

    }
    @Test
    public void test3(){



        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy/MM/dd HH");
        /**
         * 格式化  format
         */
        LocalDateTime localDate = LocalDateTime.now();
        String s = dateTimeFormatter.format(localDate);
        System.out.println(s);

        /**
         * 解析 parse
         */
        Date date = new Date() ;
//        TemporalAccessor temporalAccessor
        LocalDateTime localDateTime  = LocalDateTime.parse("2022/12/12 22",dateTimeFormatter);
       // LocalDateTime localDateTime = LocalDateTime.from(temporalAccessor);
        System.out.println(localDateTime);
    }

}
